package bknc.sgolf.services;

import java.sql.Connection;         
import java.sql.DriverManager;
import java.sql.ResultSet;          
import java.sql.SQLException;       
import java.sql.PreparedStatement;  
 



import javax.naming.Context;        
import javax.naming.InitialContext; 
import javax.sql.DataSource;        

import bknc.sgolf.beans.Country;
import bknc.sgolf.beans.GolfShop;
 
public class GolfShopInformation {           
 
    Connection conn = null;            
    PreparedStatement stmt = null;     
    String sql = null;
    GolfShop golfshop;   
    
    public GolfShop getInfo(String code) { 
 
        try {      
        	Connection conn;
            golfshop = new GolfShop();   
     
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost/bknc_sgolf", "root", "root");
            
            sql = "Select * from golfshop"; 
            
            stmt = conn.prepareStatement(sql);
            //stmt.setString(1,code); 
            ResultSet rs = stmt.executeQuery(); 
            
            while(rs.next()){ 
            	golfshop.setId(rs.getString("id").trim());
            	golfshop.setShop_name(rs.getString("shop_name").trim());
            	golfshop.setAddress(rs.getString("address").trim());
            	golfshop.setTel1(rs.getString("tel1").trim());
            	golfshop.setTel2(rs.getString("tel2").trim());
            }                                                                         
 
            rs.close();                                                               
            stmt.close();                                                             
            stmt = null;                                                              
 
 
            conn.close();                                                             
            conn = null;                                                   
 
        }                                                               
        catch(Exception e){System.out.println(e);}                      
 
        finally {                                                       
 
            if (stmt != null) {                                            
                try {                                                         
                    stmt.close();                                                
                } catch (SQLException sqlex) {                                
                    // ignore -- as we can't do anything about it here           
                }                                                             
 
                stmt = null;                                            
            }                                                        
 
            if (conn != null) {                                      
                try {                                                   
                    conn.close();                                          
                } catch (SQLException sqlex) {                          
                    // ignore -- as we can't do anything about it here     
                }                                                       
 
                conn = null;                                            
            }                                                        
        }              
 
        return golfshop;
 
    }  
 
}   
